home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.022.AutoLaunch / file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  4.3 KB  |  225 lines  |  [TEXT/MPS ]

  1. /**********************************************************************
  2. *
  3. * autolaunch file.c -- Version 3.0
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * Written by Eric Soldan.
  12. *
  13. **********************************************************************/
  14.  
  15. #include <types.h>
  16. #include <memory.h>
  17. #include <stdfile.h>
  18. #include <misctool.h>
  19.  
  20. #define __file__ 1
  21. #include "autolaunch.h"
  22.  
  23. /**********************************************************************/
  24.  
  25. void            spreadTheWord(file, theRefNum)
  26. FileIO            *file;
  27. unsigned int    theRefNum;
  28. {
  29.     /* We want the file refNum in all the structures that may be used. */
  30.  
  31.     file->close.refNum     =
  32.     file->readWrite.refNum =
  33.     file->getPos.refNum    =
  34.     file->setPos.refNum    =
  35.         theRefNum;
  36. }
  37.  
  38. /**********************************************************************/
  39.  
  40. unsigned int    openFile(file)
  41. FileIO            *file;
  42. {
  43.     static GSString255    netpath = {
  44.         17,
  45.         "@:AutoLaunch.Data"
  46.     };
  47.  
  48.     file->open.pathname = &netpath;
  49.     file->create.pathname = &netpath;
  50.  
  51.     OpenGS(&file->open);                    /* Open the file. */
  52.     if (_fileErr = _toolErr ) return(_fileErr);
  53.  
  54.     spreadTheWord(file, file->open.refNum);
  55.  
  56.     return(0);                                /* _fileErr = 0 also. */
  57. }
  58.  
  59. /**********************************************************************/
  60.  
  61. unsigned int    readFile(file)
  62. FileIO            *file;
  63. {
  64.     ReadGS(&file->readWrite);
  65.     _fileErr = _toolErr;
  66.     return(file->readWrite.transferCount);
  67. }
  68.  
  69. /**********************************************************************/
  70.  
  71. unsigned int    writeFile(file)
  72. FileIO            *file;
  73. {
  74.     WriteGS(&file->readWrite);
  75.     _fileErr = _toolErr;
  76.     return(file->readWrite.transferCount);
  77. }
  78.  
  79. /**********************************************************************/
  80.  
  81. unsigned int    closeFile(file)
  82. FileIO            *file;
  83. {
  84.     CloseGS(&file->close);
  85.     if (_fileErr = _toolErr) return(_fileErr);
  86.     spreadTheWord(file, 0);
  87.  
  88.     return(0);
  89. }
  90.  
  91. /**********************************************************************/
  92.  
  93. unsigned int    fileErr()
  94. {
  95.     if (_fileErr) ErrorWindow(0, NULL, _fileErr);
  96.     return(_fileErr);
  97. }
  98.  
  99. /**********************************************************************/
  100. /**********************************************************************/
  101. /**********************************************************************/
  102.  
  103. void    getFileInfo()
  104. {
  105.     file.info.pathname = (GSString255Ptr)launch.triggerPath;
  106.     GetFileInfo(&file.info);
  107.     if (!(_fileErr = _toolErr))
  108.         BlockMove(&file.info.modDateTime, &launch.dates[2], 8L);
  109.     return;
  110. }
  111.  
  112. /**********************************************************************/
  113.  
  114. void    getLaunchInfo()
  115. {
  116.     unsigned int    err;
  117.  
  118.     if (openFile(&file)) return;        /* We errored.  Shucks. */
  119.     readFile(&file);
  120.     err = _fileErr;
  121.     closeFile(&file);
  122.     if (err) _fileErr = err;
  123.  
  124.     if (_fileErr) {
  125.         initLaunchData();
  126.         return;
  127.     }
  128.  
  129.     getFileInfo();
  130.     if (_fileErr) {
  131.         initLaunchData();
  132.         return;
  133.     }
  134.  
  135.     if (!launch.timer) launch.timer++;
  136.     launch.dates[0] = launch.dates[2];
  137.     launch.dates[1] = launch.dates[3];
  138. }
  139.  
  140. /**********************************************************************/
  141.  
  142. void    saveLaunchInfo()
  143. {
  144.     unsigned int    err;
  145.  
  146.     openFile(&file);
  147.     if (_fileErr) {
  148.         if (_fileErr != fileNotFound) {
  149.             fileErr();
  150.             return;
  151.         }
  152.  
  153.         CreateGS(&file.create);
  154.         if (_fileErr = _toolErr) {
  155.             fileErr();
  156.             return;
  157.         }
  158.  
  159.         openFile(&file);
  160.         if (_fileErr) {
  161.             if (_fileErr != fileNotFound) {
  162.                 fileErr();
  163.                 return;
  164.             }
  165.         }
  166.     }
  167.  
  168.     writeFile(&file);
  169.     err = _fileErr;
  170.     closeFile(&file);
  171.     if (err) _fileErr = err;
  172. }
  173.  
  174. /**********************************************************************/
  175.  
  176. void            doNetCheck(initialize)
  177. unsigned int    initialize;
  178. {
  179.     unsigned long            curTime;
  180.     static unsigned long    oldTime;
  181.  
  182.     curTime = GetTick();
  183.  
  184.     if (initialize) {
  185.         oldTime = curTime;
  186.         return;
  187.     }
  188.  
  189.     updateLaunchTimer();    /* See what the user says now. */
  190.  
  191.     if (oldTime + 60 * launch.timer < curTime) {
  192.         oldTime = curTime;
  193.         getFileInfo();
  194.         if (!_fileErr) {
  195.             if (
  196.                 (launch.dates[0] != launch.dates[2]) || 
  197.                 (launch.dates[1] != launch.dates[3])
  198.             ) {
  199.                 quitFlag = 2;
  200.             }
  201.         }
  202.     }
  203.     return;
  204. }
  205.  
  206. /**********************************************************************/
  207.  
  208. unsigned int    truncFileName(path)
  209. GSString255Ptr    path;
  210. {
  211.     unsigned int    c, i, oldLen;
  212.  
  213.     oldLen = path->length;
  214.     for (i = oldLen; --i;) {
  215.         c = path->text[i];
  216.         if ((c == ':') || (c == '/')) {
  217.             path->length = i;
  218.             break;
  219.         }
  220.     }
  221.  
  222.     return(oldLen);
  223. }
  224.  
  225.